
layui.use(['layer', 'form', 'admin', 'laydate', 'ax','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //查询上级
    var pAjax = new $ax(Feng.ctxPath + "/region/selectParent", function (data) {
        $("#parentId").append(data)
    })
    pAjax.set("regionLevel","3")
    pAjax.start();
    form.render('select');

    // 让当前iframe弹层高度适应
    admin.iframeAuto();

    // 添加表单验证方法
    form.verify({
        sort: [/^[\d]{1,3}$/, '排序号为1-3位正整数']
    });

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/region/add", function (data) {
            Feng.success("添加成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });


    form.on('radio(regionLevel)',function (data) {
        var level = data.value;
        //查询上级课程
        var pAjax = new $ax(Feng.ctxPath + "/region/selectParent", function (data) {
            $("#parentId").empty();
            $("#parentId").append('<option value="">请选择上级</option>')
            $("#parentId").append(data)
        })
        pAjax.set("regionLevel",level)
        pAjax.start();
        form.render('select');
    })

});